package com.junyuan.gsp.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

public class FileUtil
{
	private static String logHome = "D:/station/logs/";
    // 解析文件扩展名
    public static String parsetExtension(String fileName)
    {
        int index = fileName.lastIndexOf(".");
        if (index < 0)
        {
            return "";
        } else
        {
            return fileName.substring(index + 1);
        }
    }

    public static void writeLog(String text)
	{
		String fileName = logHome + DateUtil.toDate(new Date()) + ".txt";
		writeLog(fileName,text);
	}

    private static void writeLog(String path, String str)
    {
        try
        {
            File file = new File(path);
            if (!file.exists())
			{
				file.createNewFile();
			}
            FileOutputStream out = new FileOutputStream(file); //true表示追加
            StringBuffer sb = new StringBuffer();
            sb.append(str + "\r\n");
            out.write(sb.toString().getBytes("utf-8"));
            out.close();
        } catch (IOException ex)
        {
            System.out.println(ex.getStackTrace());
        }
    }
}
